package com.heima.fangfa;

import java.lang.reflect.Method;

public class Method01 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        //method01();
        // method03();
        // method02();
        // method002();
       // method04();

    }

    private static void method04() throws ClassNotFoundException, NoSuchMethodException {
        //返回指定private对象的
        Class aClass = Class.forName("com.heima.fangfa.Student");
        Method show = aClass.getDeclaredMethod("show");
        System.out.println(show);
    }

    private static void method002() throws ClassNotFoundException, NoSuchMethodException {
        //返回指定public对象,有参数的
        Class aClass = Class.forName("com.heima.fangfa.Student");
        Method method = aClass.getMethod("eat", String.class);
        System.out.println(method);
    }

    private static void method02() throws ClassNotFoundException, NoSuchMethodException {
        //返回指定public对象
        Class aClass = Class.forName("com.heima.fangfa.Student");
        Method method = aClass.getMethod("drink");
        System.out.println(method);
    }

    private static void method03() throws ClassNotFoundException {
        //返回所有private、public对象的数组
        Class aClass = Class.forName("com.heima.fangfa.Student");
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethods);
        }
    }

    private static void method01() throws ClassNotFoundException {
        Class aClass = Class.forName("com.heima.fangfa.Student");
        //返回所有public对象的数组，包含继承的
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }
}
